package ModelLayer;


import java.util.ArrayList;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * The test class AddressBookTest.
 *
 * @author  (your name)
 * @version (a version number or a date)
 */
public class AddressBookTest
{
    /**
     * Default constructor for test class AddressBookTest
     */
    public AddressBookTest()
    {
    }

    /**
     * Sets up the test fixture.
     *
     * Called before every test case method.
     */
    @Before
    public void setUp()
    {
    }

    /**
     * Tears down the test fixture.
     *
     * Called after every test case method.
     */
    @After
    public void tearDown()
    {
    }
    
   

    @Test
    public void testGetInstance()
    {
        assertNotNull(ModelLayer.AddressBook.getInstance());
    }
    
    @Test
    public void testAddPerson()
    {
        Person newPerson=new Person(8, "stoqn", "zaxariev", 92, "Sofia", 923942);
        boolean status=false;
        ModelLayer.AddressBook.getInstance().addPerson(newPerson);
        ArrayList<Person> persons = ModelLayer.AddressBook.getInstance().getPersonlist();
        for(Person person: persons)
            {
                if (person==newPerson)  status = true;
                else status = false; 
            }
        
            assertTrue("this is wrong", status);                
    }
    
    
    @Test
    public void testRemovePerson()
    {
        Person person=new Person(8, "stoqn", "zaxariev", 92, "Sofia", 923942);
        boolean status=false;
        person.setId(1);
        ModelLayer.AddressBook.getInstance().removePerson(1);
        ArrayList<Person> persons = ModelLayer.AddressBook.getInstance().getPersonlist();
        for(Person curPerson : persons)
        {
            if (curPerson==person) status = true;
            else status = false;
        }
        assertFalse("Test fails", status);
    }
    
    
   @Test
   public void testGetPerson()
   {
       Person person = new Person ( 8, "stoi4ko","zahariev", 929,"Sofia",192213);
       AddressBook.getInstance().addPerson(person);
       assertNotNull(AddressBook.getInstance().getPerson(8));
   }
    
    
   @Test
   public void testUpdatePerson()
   {
      Person person = new Person( 8, "stoi4ko","zahariev", 929,"Sofia",192213);
      AddressBook.getInstance().addPerson(person);
      AddressBook.getInstance().updatePerson(1,8,"madalin4o");
      assertEquals("madalin4o",AddressBook.getInstance().getPerson(8).getName());
   }
    
   
   
   
}

